home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / dflat2.zip / DFLAT.H < prev    next >
Text File  |  1991-04-19  |  11KB  |  273 lines

  1. /* ------------- dflat.h ----------- */
  2.  
  3. #ifndef WINDOW_H
  4. #define WINDOW_H
  5.  
  6. #define VERSION "Version 2 Beta"
  7.  
  8. #define TRUE 1
  9. #define FALSE 0
  10.  
  11. #include "system.h"
  12. #include "config.h"
  13. #include "rect.h"
  14. #include "menu.h"
  15. #include "keys.h"
  16. #include "commands.h"
  17. #include "config.h"
  18. #include "dialbox.h"
  19.  
  20. /* ------ integer type for message parameters ----- */
  21. typedef long PARAM;
  22. typedef enum window_class    {
  23.     NORMAL,
  24.     APPLICATION,
  25.     TEXTBOX,
  26.     LISTBOX,
  27.     EDITBOX,
  28.     MENUBAR,
  29.     POPDOWNMENU,
  30.     BUTTON,
  31.     DIALOG,
  32.     ERRORBOX,
  33.     MESSAGEBOX,
  34.     HELPBOX,
  35.     TEXT,
  36.     RADIOBUTTON,
  37.     DUMMY
  38. } CLASS;
  39. typedef struct window {
  40.     CLASS class;           /* window class                  */
  41.     char *title;           /* window title                  */
  42.     struct window *parent; /* parent window                 */
  43.     int (*wndproc)
  44.         (struct window *, enum messages, PARAM, PARAM);
  45.     /* ---------------- window dimensions ----------------- */
  46.     RECT rc;               /* window coordinates
  47.                                             (0/0 to 79/24)  */
  48.     int ht, wd;            /* window height and width       */
  49.     RECT RestoredRC;       /* restored condition rect       */
  50.     /* -------------- linked list pointers ---------------- */
  51.     struct window *next;        /* next window on screen    */
  52.     struct window *prev;        /* previous window on screen*/
  53.     struct window *nextbuilt;   /* next window built        */
  54.     struct window *prevbuilt;   /* previous window built    */
  55.  
  56.     int attrib;                 /* Window attributes        */
  57.     char *videosave;            /* video save buffer        */
  58.     int condition;              /* Restored, Maximized,
  59.                                            Minimized        */
  60.     int restored_attrib;        /* attributes when restored */
  61.     void *extension;            /* -> menus, dialog box, etc*/
  62.     struct window *PrevMouse;
  63.     struct window *PrevKeyboard;
  64.     /* ----------------- text box fields ------------------ */
  65.     int wlines;     /* number of lines of text              */
  66.     int wtop;       /* text line that is on the top display */
  67.     char *text;     /* window text                          */
  68.     int textlen;    /* text length                          */
  69.     int wleft;      /* left position in window viewport     */
  70.     int textwidth;  /* width of longest line in textbox     */
  71.     int BlkBegLine; /* beginning line of marked block       */
  72.     int BlkBegCol;  /* beginning column of marked block     */
  73.     int BlkEndLine; /* ending line of marked block          */
  74.     int BlkEndCol;  /* ending column of marked block        */
  75.     int HScrollBox; /* position of horizontal scroll box    */
  76.     int VScrollBox; /* position of vertical scroll box      */
  77.     /* ------------------ list box field ------------------ */
  78.     int selection;  /* current selection                    */
  79.     /* ----------------- edit box fields ------------------ */
  80.     int CurrCol;    /* Current column                       */
  81.     char *CurrLine; /* Current line                         */
  82.     int WndRow;     /* Current window row                   */
  83.     int TextChanged; /* TRUE if text has changed            */
  84.     char *DeletedText; /* for undo                          */
  85.     int DeletedLength; /*  "   "                            */
  86.     /* ---------------- dialog box fields ----------------- */
  87.     struct window *dFocus; /* control that has the focus    */
  88.     int ReturnCode;        /* return code from a dialog box */
  89. } * WINDOW;
  90.  
  91. #include "message.h"
  92. #include "classdef.h"
  93. #include "video.h"
  94.  
  95. enum Condition     {
  96.     ISRESTORED, ISMINIMIZED, ISMAXIMIZED
  97. };
  98. /* ------- window methods ----------- */
  99. #define WindowHeight(w)      ((w)->ht)
  100. #define WindowWidth(w)       ((w)->wd)
  101. #define BorderAdj(w,n)       (TestAttribute(w,HASBORDER)?n:0)
  102. #define ClientWidth(w)       (WindowWidth(w)-BorderAdj(w,2))
  103. #define ClientHeight(w)      (WindowHeight(w)-BorderAdj(w,2))
  104. #define WindowRect(w)        ((w)->rc)
  105. #define GetTop(w)            (RectTop(WindowRect(w)))
  106. #define GetBottom(w)         (RectBottom(WindowRect(w)))
  107. #define GetLeft(w)           (RectLeft(WindowRect(w)))
  108. #define GetRight(w)          (RectRight(WindowRect(w)))
  109. #define GetClientTop(w)      (GetTop(w)+BorderAdj(w,1))
  110. #define GetClientBottom(w)   (GetBottom(w)-BorderAdj(w,1))
  111. #define GetClientLeft(w)     (GetLeft(w)+BorderAdj(w,1))
  112. #define GetClientRight(w)    (GetRight(w)-BorderAdj(w,1))
  113. #define GetParent(w)         ((w)->parent)
  114. #define GetTitle(w)          ((w)->title)
  115. #define NextWindow(w)        ((w)->next)
  116. #define PrevWindow(w)        ((w)->prev)
  117. #define NextWindowBuilt(w)   ((w)->nextbuilt)
  118. #define PrevWindowBuilt(w)   ((w)->prevbuilt)
  119. #define GetClass(w)          ((w)->class)
  120. #define GetAttribute(w)      ((w)->attrib)
  121. #define AddAttribute(w,a)    (GetAttribute(w) |= a)
  122. #define ClearAttribute(w,a)  (GetAttribute(w) &= ~(a))
  123. #define TestAttribute(w,a)   (GetAttribute(w) & (a))
  124. #define isVisible(w)         (GetAttribute(w) & VISIBLE)
  125. #define SetVisible(w)        (GetAttribute(w) |= VISIBLE)
  126. #define ClearVisible(w)      (GetAttribute(w) &= ~VISIBLE)
  127. #define gotoxy(w,x,y) cursor(w->rc.lf+(x)+1,w->rc.tp+(y)+1)
  128. WINDOW CreateWindow(CLASS,char *,int,int,int,int,void*,WINDOW,
  129.         int (*)(struct window *,enum messages,PARAM,PARAM),int);
  130. void AddTitle(WINDOW, char *);
  131. void RepaintBorder(WINDOW, RECT *);
  132. void ClearWindow(WINDOW, RECT *, int);
  133. void clipline(WINDOW, int, char *);
  134. void writeline(WINDOW, char *, int, int, int);
  135. void writefull(WINDOW, char *, int);
  136. void SetNextFocus(WINDOW,int);
  137. void PutWindowChar(WINDOW, int, int, int);
  138. void GetVideoBuffer(WINDOW);
  139. void RestoreVideoBuffer(WINDOW);
  140. int LineLength(char *);
  141. #define DisplayBorder(wnd) RepaintBorder(wnd, NULL)
  142. #define DefaultWndProc(wnd,msg,p1,p2)    \
  143.     classdefs[FindClass(wnd->class)].wndproc(wnd,msg,p1,p2)
  144. #define BaseWndProc(class,wnd,msg,p1,p2)    \
  145.     classdefs[DerivedClass(class)].wndproc(wnd,msg,p1,p2)
  146. #define NULLWND ((WINDOW) 0)
  147. struct LinkedList    {
  148.     WINDOW FirstWindow;
  149.     WINDOW LastWindow;
  150. };
  151. extern struct LinkedList Focus;
  152. extern struct LinkedList Built;
  153. extern WINDOW inFocus;
  154. extern WINDOW CaptureMouse;
  155. extern WINDOW CaptureKeyboard;
  156. extern int foreground, background;
  157. extern int WindowMoving;
  158. extern int WindowSizing;
  159. extern int TextMarking;
  160. extern char *Clipboard;
  161. extern WINDOW SystemMenuWnd;
  162. /* --------------- border characters ------------- */
  163. #define FOCUS_NW       '\xc9'
  164. #define FOCUS_NE       '\xbb'
  165. #define FOCUS_SE       '\xbc'
  166. #define FOCUS_SW       '\xc8'
  167. #define FOCUS_SIDE     '\xba'
  168. #define FOCUS_LINE     '\xcd'
  169. #define NW             '\xda'
  170. #define NE             '\xbf'
  171. #define SE             '\xd9'
  172. #define SW             '\xc0'
  173. #define SIDE           '\xb3'
  174. #define LINE           '\xc4'
  175. #define LEDGE          '\xc3'
  176. #define REDGE          '\xb4'
  177. #define SHADOWFG       DARKGRAY
  178. /* ------------- scroll bar characters ------------ */
  179. #define UPSCROLLBOX    '\x1e'
  180. #define DOWNSCROLLBOX  '\x1f'
  181. #define LEFTSCROLLBOX  '\x11'
  182. #define RIGHTSCROLLBOX '\x10'
  183. #define SCROLLBARCHAR  176 
  184. #define SCROLLBOXCHAR  178
  185. #define CHECKMARK      251      /* menu item toggle         */
  186. /* ----------------- title bar characters ----------------- */
  187. #define CONTROLBOXCHAR '\xf0'
  188. #define MAXPOINTER     24      /* maximize token            */
  189. #define MINPOINTER     25      /* minimize token            */
  190. #define RESTOREPOINTER 18      /* restore token             */
  191. /* --------------- text control characters ---------------- */
  192. #define APPLCHAR     176    /* fills application window     */
  193. #define SHORTCUTCHAR '~'    /* prefix: shortcut key display */
  194. #define CHANGECOLOR  174    /* prefix to change colors      */
  195. #define RESETCOLOR   175    /* reset colors to default      */
  196. /* ---- standard window message processing prototypes ----- */
  197. int ApplicationProc(WINDOW, MESSAGE, PARAM, PARAM);
  198. int NormalProc(WINDOW, MESSAGE, PARAM, PARAM);
  199. int TextBoxProc(WINDOW, MESSAGE, PARAM, PARAM);
  200. int ListBoxProc(WINDOW, MESSAGE, PARAM, PARAM);
  201. int EditBoxProc(WINDOW, MESSAGE, PARAM, PARAM);
  202. int MenuBarProc(WINDOW, MESSAGE, PARAM, PARAM);
  203. int PopDownProc(WINDOW, MESSAGE, PARAM, PARAM);
  204. int ButtonProc(WINDOW, MESSAGE, PARAM, PARAM);
  205. int DialogProc(WINDOW, MESSAGE, PARAM, PARAM);
  206. int SystemMenuProc(WINDOW, MESSAGE, PARAM, PARAM);
  207. int HelpBoxProc(WINDOW, MESSAGE, PARAM, PARAM);
  208. int MessageBoxProc(WINDOW, MESSAGE, PARAM, PARAM);
  209. /* ------------- normal box prototypes ------------- */
  210. int isWindow(WINDOW);
  211. WINDOW inWindow(int, int);
  212. int WndForeground(WINDOW);
  213. int WndBackground(WINDOW);
  214. int FrameForeground(WINDOW);
  215. int FrameBackground(WINDOW);
  216. int SelectForeground(WINDOW);
  217. int SelectBackground(WINDOW);
  218. void SetStandardColor(WINDOW);
  219. void SetReverseColor(WINDOW);
  220. void SetClassColors(CLASS);
  221. WINDOW GetFirstChild(WINDOW);
  222. WINDOW GetNextChild(WINDOW);
  223. WINDOW GetLastChild(WINDOW);
  224. WINDOW GetPrevChild(WINDOW);
  225. #define HitControlBox(wnd, p1, p2)     \
  226.     (TestAttribute(wnd, TITLEBAR)   && \
  227.      TestAttribute(wnd, CONTROLBOX) && \
  228.      p1 == 2 && p2 == 0)
  229. /* -------- text box prototypes ---------- */
  230. char *TextLine(WINDOW, int);
  231. void WriteTextLine(WINDOW, RECT *, int, int);
  232. void SetTextBlock(WINDOW, int, int, int, int);
  233. #define BlockMarked(wnd) (  wnd->BlkBegLine ||    \
  234.                             wnd->BlkEndLine ||    \
  235.                             wnd->BlkBegCol  ||    \
  236.                             wnd->BlkEndCol)
  237. #define ClearBlock(wnd) wnd->BlkBegLine = wnd->BlkEndLine =  \
  238.                         wnd->BlkBegCol  = wnd->BlkEndCol = 0;
  239. #define GetText(w)        ((w)->text)
  240. /* --------- menu prototypes ---------- */
  241. int CopyCommand(char *, char *, int, int);
  242. void PrepOptionsMenu(void *, struct Menu *);
  243. void PrepEditMenu(void *, struct Menu *);
  244. void PrepWindowMenu(void *, struct Menu *);
  245. void BuildSystemMenu(WINDOW);
  246. /* ------------- edit box prototypes ----------- */
  247. #define isMultiLine(wnd)     TestAttribute(wnd, MULTILINE)
  248. /* --------- message box prototypes -------- */
  249. void MessageBox(char *, char *);
  250. void ErrorMessage(char *);
  251. int TestErrorMessage(char *);
  252. int YesNoBox(char *);
  253. int MsgHeight(char *);
  254. int MsgWidth(char *);
  255. /* ------------- dialog box prototypes -------------- */
  256. int DialogBox(WINDOW, DBOX *,
  257.         int (*)(struct window *, enum messages, PARAM, PARAM));
  258. int DlgOpenFile(char *, char *);
  259. int DlgSaveAs(char *);
  260. void GetDlgListText(WINDOW, char *, enum commands);
  261. int DlgDirList(WINDOW, char *, enum commands,
  262.                             enum commands, unsigned);
  263. int RadioButtonSetting(DBOX *, enum commands);
  264. void PushRadioButton(DBOX *, enum commands);
  265. void PutItemText(WINDOW, enum commands, char *);
  266. void GetItemText(WINDOW, enum commands, char *, int);
  267. /* ------------- help box prototypes ------------- */
  268. void HelpFunction(void);
  269. void LoadHelpFile(void);
  270. #define swap(a,b){int x=a;a=b;b=x;}
  271.  
  272. #endif
  273.